﻿//867.转置矩阵
/**
 * Return an array of arrays of size *returnSize.
 * The sizes of the arrays are returned as *returnColumnSizes array.
 * Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
 */
int** transpose(int** matrix, int matrixSize, int* matrixColSize, int* returnSize, int** returnColumnSizes) {
    int m = matrixSize;
    int n = (*matrixColSize);

    int** ans = (int**)malloc(sizeof(int*) * n);
    *returnColumnSizes = (int*)malloc(sizeof(int) * n);

    for (int i = 0; i < n; i++)
    {
        ans[i] = (int*)malloc(sizeof(int) * m);
        (*returnColumnSizes)[i] = m;
        for (int j = 0; j < m; j++)
        {
            ans[i][j] = matrix[j][i];
        }
    }
    *returnSize = n;
    return ans;
}